#!/bin/sh -xe

# https://github.com/QuasarApp/CQtDeployer/issues/766

# env
procs=`nproc --all`
export PATH=$PATH:/opt/Qt/6.6.3/gcc_64/bin
epport LIBRARY_PATH=$LIBRARY_PATH:/opt/Qt/6.6.3/gcc_64/lib:/usr/lib:/usr/lib/x86_64-linux-gnu
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt/6.6.3/gcc_64/lib:/usr/lib:/usr/lib/x86_64-linux-gnu

# build
cmake -S /workspace/QmlClient -B /workspace/QmlClient/build
cd /workspace/QmlClient/build && make -j${procs}

# copy
mkdir /workspace/QmlClient/deploy
cp /workspace/QmlClient/build/appQmlClient /workspace/QmlClient/deploy/appQmlClient

# deploy
cd /workspace/QmlClient/deploy
cqtdeployer -bin appQmlClient -qmlDir /opt/Qt/6.6.3/gcc_64/qml \
            -qmake /opt/Qt/6.6.3/gcc_64/bin/qmake  \
            -targetDir /workspace/QmlClient/deploy/dist \
            -verbose 3

# copy resource
cp /opt/Qt/6.6.3/gcc_64/lib/libicui18n.so.56 /workspace/QmlClient/deploy/dist/lib
cp /opt/Qt/6.6.3/gcc_64/lib/libicuuc.so.56 /workspace/QmlClient/deploy/dist/lib
cp /opt/Qt/6.6.3/gcc_64/lib/libicudata.so.56 /workspace/QmlClient/deploy/dist/lib
cp -r /workspace/QmlClient/build/HtmlTemplate /workspace/QmlClient/deploy/dist/bin/HtmlTemplate
cp /workspace/QmlClient/build/qml-config.ini /workspace/QmlClient/deploy/dist/bin/qml-config.ini

# rm
rm /workspace/QmlClient/deploy/appQmlClient

